package com.mixsmart.web.plugins.controller;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mixsmart.commonweb.plugins.IPlugin;
import com.mixsmart.commonweb.plugins.PluginFactory;
import com.mixsmart.core.bean.MixResponse;
import com.mixsmart.utils.StringUtils;
import com.mixsmart.web.controller.BaseWebController;
import com.mixsmart.web.plugins.bean.AutoComplete;

/**
 * 自动填充插件控制器
 * @author lmq
 * @version 1.0
 * @since 1.0
 * <br />
 * 2016年7月3日
 */
@Controller
@RequestMapping("/autoComplete")
public class AutoCompleteController extends BaseWebController {

	@Autowired
	@Qualifier("autoComplete")
	private IPlugin autoComplete;
	
	/**
	 *  通过资源名称查询获取AutoComplete插件的数据结构
	 * @param request HttpServletRequest对象
	 * @param resName 资源名称（SQL名称）
	 * @return 返回MixResponse<Object>对象，以JSON格式方式返回给前台页面；
	 * <p>如果成功查询到数据；则getResult()方法返回值为“1”</p>
	 */
	@RequestMapping("/query/{resName}.do")
	@ResponseBody
	public MixResponse<AutoComplete> query(HttpServletRequest request,@PathVariable String resName) {
		MixResponse<AutoComplete> mixResp = new MixResponse<AutoComplete>();
		if(StringUtils.isNotEmpty(resName)) {
			HashMap<String, Object> params = getRequestParamMap(request);
			mixResp = PluginFactory.getPluginDatas(autoComplete, resName, params);
			params = null;
		}
		return mixResp;
	}
	
}
